/*Sign up function */
var _currentID;
function signUpWithOption(optionSignUp){
    var username = $('#username').val();
    var password = $('#password').val();
    var confirmpass = $('#confirmpassword').val();
    var email = $('#email').val();
    var error = 0;
    if(username ==''){
	$('#signuperror').html('Please input username');
            $('#username').focus();
            error = 1;
	}
        if(password ==''){
            $('#signuperror').html('Please input password');
            error = 1;
        }
        if(password!= confirmpass){
            $('#signuperror').html('Password not match');
            error =1;
        }
        var user = new Parse.User();
        user.set("username", username);
        user.set("password", password);
        user.set("email", email);

        user.signUp(null, {
          success: function(user) {
            $('#signuperror').html('Sign up successful');
             Parse.User.logIn(username, password, {
                success: function(user) {     
                    switch(optionSignUp){
                        case 0:
                            window.location = baseurl;
                        break;
                        case 1:{
                            //sign up with facebook
                        }
                        break;
                        case 2:{//sign up with twitter
                            
                        }
                        break;
                        default:
                        break;
                    }
                },
                error: function(user, error) {
                }
              });
          },
          error: function(user, error) {
              $('#signuperror').html(error.message);
          }
        });
}


function signUpTwitter(){
    
}
function signUpFacebook(){
    /*
    Parse.FacebookUtils.logIn(null, {
  success: function(user) {
    if (!user.existed()) {
      alert("User signed up and logged in through Facebook!");
    } else {
      alert("User logged in through Facebook!");
    }
  },
  error: function(user, error) {
    alert("User cancelled the Facebook login or did not fully authorize.");
  }*/
}
$(document).ready(function(){
    $('#submitsignup').click(function(){
        signUpWithOption(0);
    });
    $('#submitsignupFaebook').click(function(){
        signUpWithOption(1);
    });
    $('#submitsignupTwitter').click(function(){
        signUpWithOption(2);
    });
});
    
